﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Framework;
using CNVP.Framework.Utils;
using CNVP.JShop.BLL;

namespace CNVP.JShop.Web.Admin
{
    public partial class ProductAdd : AdminPage
    {
        BLL.CNVP_Products bll = new BLL.CNVP_Products();
        Model.CNVP_Products model = new Model.CNVP_Products();
        public int id = 0;
        public string TypeEdit = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 21)) return;//判断页面权限
            if (Request.QueryString["ID"] != null && Request.QueryString["ID"].ToString() != "" && Public.IsNumber(Request.QueryString["ID"].ToString()))
            {
                id = Convert.ToInt32(Request.QueryString["ID"].ToString());
            }
            if (Request.QueryString["TypeEdit"] != null && Request.QueryString["TypeEdit"].ToString() != "")
            {
                TypeEdit = Request.QueryString["TypeEdit"].ToString();
            }
            if (!Page.IsPostBack)
            {
                ProductClassIDBind();
                ddlProductTypeIDBind();
                ddlDeliveryFreighBind();
                if (id > 0)
                {
                    btUp1.Visible = false;
                    string TypeStr = "";
                    if (TypeEdit == "up")
                    {
                        TypeStr = "<a href=\"ProductListUp.aspx\">上架商品</a>";
                    }
                    else if (TypeEdit == "down")
                    {
                        TypeStr = "<a href=\"ProductListDown.aspx\">下架商品</a>";
                    }
                    else if (TypeEdit == "clear")
                    {
                        TypeStr = "<a href=\"ProductListClear.aspx\">回收站</a>";
                    }
                    else
                    {
                        TypeStr = "<a href=\"ProductList.aspx\">商品管理</a>";
                    }
                    lbTitle.Text = TypeStr + " > 修改";
                    DataInfo(id);
                    Page.Title = ViewState["ProductName"].ToString();
                    //////////////////////////////////////SEO/////////////////////
                    
                }
                else
                {
                    string TypeStr = "<a href=\"ProductList.aspx\">商品管理</a>";
                    lbTitle.Text = TypeStr + " > 添加";
                    Page.Title = "产品添加";
                }
                HotProList();
                #region 验证
                ddlProductTypeID.Attributes.Add("onchange", "ProTypeRefBranks();ProductType();");
                #endregion
            }
           
        }
        //商品分类
        private void ProductClassIDBind()
        {
            new BLL.BLLColumn().BuildAllDDList(this.ddlProductClassID,3);
        }
       
        //商品类型
        private void ddlProductTypeIDBind()
        {
            ddlProductTypeID.DataSource = new BLL.CNVP_ProductType().LoadAllUseDropDownList();
            ddlProductTypeID.DataTextField = "ProTypeName";
            ddlProductTypeID.DataValueField = "ID";
            ddlProductTypeID.DataBind();
        }

        //运费模板
        private void ddlDeliveryFreighBind()
        {
            new BLL.BLLColumn().BuildAllDDList(this.ddlDeliveryFreight, 4);
        }

        private void HotProList()
        {
            string AddTr = "";
            AddTr += "<table id=\"tableEditPic\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
            if (txtHotLink.Text.Trim() != "")
            {
                string[] resultArray = txtHotLink.Text.Trim().Split(Convert.ToChar(","));
                for (int i = 0; i < resultArray.Length; i++)
                {
                    Model.CNVP_Products model = new Model.CNVP_Products();
                    BLL.CNVP_Products bll = new BLL.CNVP_Products();
                    model = bll.GetSingle_CNVP_ProductsById(int.Parse(resultArray[i]));
                    if (model != null)
                    {
                        AddTr += "<tr id=\"tr" + (i + 1) + "\">";
                        AddTr += "<td style=\"width=30px;\">";
                        AddTr += i + 1;
                        AddTr += "</td>";
                        AddTr += "		<td style=\"width:100px;\">";
                        AddTr += "         <a href=\"/ProductDetail_" + model.ProductClassID + "_" + model.ID + ".aspx\" target=\"_blank\" title=\"" + model.ProductName + "\">";
                        AddTr += "		    <img src=\"/UploadFile/Product/" + model.ImgProLoad + "\"  class=\"BuyIsPrintPic\"> ";
                        AddTr += "         </a>";
                        AddTr += "      <input type=\"hidden\" id=\"ImgProLoad\" name=\"ImgProLoad\" value=\"" + model.ImgProLoad + "\" />";
                        AddTr += "		</td>";
                        AddTr += "		<td style=\"text-align:left;vertical-align:middle;\">";
                        AddTr += "         <a href=\"/ProductDetail_" + model.ProductClassID + "_" + model.ID + ".aspx\" target=\"_blank\" title=\"" + model.ProductName + "\">";
                        AddTr += "      " + model.ProductName + "";
                        AddTr += "         </a>";
                        AddTr += "      <input type=\"hidden\" id=\"ProductName\" name=\"ProductName\" value=\"" + model.ProductName + "\" />";
                        AddTr += "		</td>";
                        AddTr += "<td style=\"width:200px;vertical-align:middle;\">";
                        
                        AddTr += "<a onclick=\"onMoveUp(this)\"  style=\"cursor:pointer\"> ";
                        AddTr += "向上";
                        AddTr += "</a>";
                        AddTr += "<a onclick=\"onMoveDown(this)\" style=\"cursor:pointer\"> ";
                        AddTr += "向下";
                        AddTr += "</a>";
                        AddTr += "</td>";
                            
                        AddTr += "		<td style=\"width:20px;vertical-align:middle;\">";
                        //AddTr += "		<input id=\"BTDel\" type=\"button\" value=\"删除\" onclick='Del(" + resultArray[i] + ")' />";
                        AddTr += "		<input id=\"BTDel\" type=\"button\" value=\"删除\" onclick='onDelete(this)' />"; // Del(" + (i + 1) + ")
                        AddTr += "      <input type=\"hidden\" id=\"ProductID\" name=\"ProductID\" value=\"" + resultArray[i] + "\" />";
                        AddTr += "		</td>";
                        AddTr += "	</tr>";
                    }
                }
            }
            AddTr += "</table>";
            lbHotProList.Text = AddTr;
        }

        public void DataInfo(int id)
        {
            model = bll.GetSingle_CNVP_ProductsById(id);
            if (model != null)
            {
                ddlProductClassID.SelectedValue = model.ProductClassID.ToString();
                ddlProductTypeID.SelectedValue = model.ProductTypeID.ToString();
                txtProductName.Text = model.ProductName;
                ViewState["ProductName"] = model.ProductName;
                txtProductCode.Text = model.ProductCode;
                txtKeyWords.Text = model.KeyWords;
                lbProBrandID.Text = model.BrandID.ToString();//产品品牌ID
                Standard.Value = model.StandardIDs;
                StandardName.Value = model.StandardValues;
                txtProductUnit.Text = model.ProductUnit;
                txtIntro.Text = model.Intro;
                rblProductState.SelectedValue = model.ProductState.ToString();
                txtTradePrice.Text = model.TradePrice.ToString();
                txtCostPrice.Text = model.CostPrice.ToString();
                txtMarketPrice.Text = model.MarketPrice.ToString();
                txtProductNo.Text = model.ProductNo;
                txtProductWeight.Text = model.ProductWeight.ToString();
                txtStockTotalNum.Text = model.StockTotalNum.ToString();
                txtAllocation.Text = model.Allocation;
                txtProductTags.Text = model.ProductTags;
                FCKeditor1.Value = model.Detaile;
                txtImgProLoad.Text = model.ImgProLoad;
                ViewState["seoInId"] = model.SeoInfoID;
                txtHotLink.Text = model.HotLink;
                rbAllowReview.SelectedValue = model.AllowReview.ToString();
                ddlDeliveryFreight.SelectedValue = model.DeliveryFreightID.ToString();
                //图片
                var Addb = "";
                var Pic_List = new BLL.CNVP_ProductsPic().GetAll_CNVP_ProductsPic(id);
                for (int i = 0; i < Pic_List.Count; i++)
                {
                    Addb += "<li id=\"b" + Pic_List[i].ID + "\" style=\"list-style-type:none;border:3px #e2e2e2 solid; margin:5px 5px 5px 0px; padding:2px 2px 2px 2px; float:left\">";
                    Addb += "<span>";
                    Addb += "	<img alt=\"\" src='../UploadFile/Product/" + Pic_List[i].SmallPic + "' id=\"ImgPic" + Pic_List[i].ID + "\" name=\"ImgPic\" width=\"70px\" height=\"70px\"  onclick=\"SelectImg('" + Pic_List[i].ID + "','" + Pic_List[i].Pic + "');\"/>";
                    Addb += "	<input type=\"hidden\" id=\"PicAddressA" + Pic_List[i].ID + "\" name=\"PicAddressA\" value='" + Pic_List[i].SmallPic + "'  />";
                    Addb += "	<input type=\"hidden\" id=\"PicAddressB" + Pic_List[i].ID + "\" name=\"PicAddressB\" value='" + Pic_List[i].Pic+ "' />";
                    Addb += "	<input type=\"hidden\" id=\"PicAddressC" + Pic_List[i].ID + "\" name=\"PicAddressC\" value='" + Pic_List[i].BigPic + "' />";
                    Addb += "	<input type=\"hidden\" id=\"PicAddressD" + Pic_List[i].ID + "\" name=\"PicAddressD\" value='" + Pic_List[i].OriginalPic + "' />";
                    Addb += "	<input id=\"cbUploadImg\" type=\"checkbox\" checked=\"checked\" name=\"cbUploadImg\" value='" + Pic_List[i].ID + "' class=\"Display\" />";
                    Addb += "</span>";
                    Addb += "<br /><span id=\"" + (i + 1) + "\"><a href=\"javascript:void(0)\" class=\"up" + Pic_List[i].ID + "\" onclick=\"up(" + Pic_List[i].ID + ")\"><img src=\"/Admin/Images/up.jpg\" border=\"0\"/></a><a href=\"javascript:void(0)\" class=\"down" + Pic_List[i].ID + "\" onclick=\"down(" + Pic_List[i].ID + ")\"><img src=\"/Admin/Images/down.jpg\" border=\"0\"/></a><a href=\"javascript:void(0)\" class=\"del" + Pic_List[i].ID + "\" onclick=\"del(" + Pic_List[i].ID + ")\"><img src=\"/Admin/Images/delete.jpg\" border=\"0\"/></a></span>";
                    Addb += "</li>";
                }
                LiterPic.Text = Addb;
                //产品详细
                #region 详细产品
                var list_ProductsDetail = new BLL.CNVP_ProductsDetail().GetAll_CNVP_ProductsDetail(id);
                if (list_ProductsDetail.Count > 0)
                {
                    string[] standardvalue = model.StandardValues.Split(Convert.ToChar(","));

                    var AddTr = "";
                    AddTr += "<table id=\"tableEdit\">";
                    AddTr += "	 <tr>";
                    AddTr += "	 <td >";
                    AddTr += "		</td>";
                    AddTr += "	<td >";
                    AddTr += "		<input id=\"CKA\" name=\"CKA\" type=\"checkbox\" onclick=\"CKACheck()\" /></td>";
                    AddTr += "	<td >";
                    AddTr += "		货号</td>";
                    AddTr += "	";
                    var html = "";
                    for (var k = 0; k < standardvalue.Length; k++)
                    {
                        html += "	<td >";
                        html += standardvalue[k];
                        html += "	 </td>";
                    }
                    AddTr += html;
                    AddTr += "	 <td >";
                    AddTr += "		库存</td>";
                    AddTr += "	<td >";
                    AddTr += "		销售价</td>";
                    AddTr += "	<td >";
                    AddTr += "		市场价</td>";
                    AddTr += "	<td >";
                    AddTr += "		成本价</td>";
                    AddTr += "	<td >";
                    AddTr += "		重量</td>";
                    AddTr += "	<td >";
                    AddTr += "		货位</td>";
                    AddTr += "	<td >";
                    AddTr += "		上架</td>";
                    AddTr += "</tr>";
                    string TrRows = "";
                    for (int i = 0; i < list_ProductsDetail.Count; i++)
                    {
                        TrRows += "<tr>";
                        TrRows += "	<td >" + (i + 1) + "</td>";
                        TrRows += "	<td >";
                        TrRows += "		<input id=\"CK\" name=\"CK\" type=\"checkbox\"  value=\"" + list_ProductsDetail[i].ID + "\" /><input id=\"CKProDetail\" name=\"CKProDetail\" type=\"checkbox\" checked=\"checked\" class =\"Display\" value=\"" + list_ProductsDetail[i].ID + "\" /></td>";
                        TrRows += "	<td>";
                        TrRows += "		<input id=\"ProDetailNo" + list_ProductsDetail[i].ID + "\" type=\"text\" name=\"ProDetailNo\" value=\"" + list_ProductsDetail[i].ProDetailNo + "\" maxlength=\"50\" /></td>";
                        string optionNull = "";
                        string[] standardids = model.StandardIDs.Split(Convert.ToChar(",")); ;
                        for (int j = 0; j < standardids.Length; j++)
                        {
                            int StandardValueID = 0;
                            string[] StandardValueIDsArray = list_ProductsDetail[i].StandardValueIDs.Split(Convert.ToChar(","));
                           
                             StandardValueID = int.Parse(StandardValueIDsArray[j]);//产品详细表。数量和规格数量相同，所有用‘，’
                            
                            string ddlID = standardids[j].ToString();
                            string StandardType_Str = new BLL.CNVP_Standard().GetSingle_CNVP_StandardById(int.Parse(ddlID)).StandardType.ToString();
                            if (StandardType_Str == "2")
                            {
                                string picUrl = new BLL.CNVP_StandardValue().GetSingle_CNVP_StandardValueById(StandardValueID).StandardValuePic;
                                optionNull += "<td>";
                                optionNull += "<img id=\"img" + ddlID + "" + list_ProductsDetail[i].ID + "\" width=\"50\" height=\"50\" src=\""+ picUrl + "\" onclick=\"showtopic(" + ddlID + "," + list_ProductsDetail[i].ID + ")\" style =\"cursor:hand;\" />";
                                optionNull += "<input id=\"text" + ddlID + "" + list_ProductsDetail[i].ID + "\" type=\"hidden\" name=\"StandardValueID" + ddlID + "\" value=\"" + StandardValueID + "\" />";//注意：不管是图片，还文本框都是规格值‘StandardValueID’
                                optionNull += "</td>";
                            }
                            else
                            {
                                optionNull += "<td>";
                                optionNull += "<select id=\"ddl" + list_ProductsDetail[i].ID + "\" name=\"StandardValueID" + ddlID + "\">";
                                optionNull += "<option value=\"0\">请选择</option>";
                                var list_StandardValue = new BLL.CNVP_StandardValue().GetAll_CNVP_StandardValue(int.Parse(ddlID));
                                for (int a = 0; a < list_StandardValue.Count; a++)
                                {
                                    string selectCB = "";
                                    if (StandardValueID == list_StandardValue[a].ID)
                                    {
                                        selectCB = "selected='selected'";
                                    }
                                    optionNull += " <option value=\"" + list_StandardValue[a].ID + "\" " + selectCB + ">" + list_StandardValue[a].StandardValueName + "</option>";
                                }
                                optionNull += "</select>";
                                optionNull += "</td>";
                            }
                        }
                        TrRows += optionNull;
                        TrRows += "	<td>";
                        TrRows += "		<input id=\"StockNum" + list_ProductsDetail[i].ID + "\" onblur=\"SetStockNum();\"  type=\"text\" name=\"StockNum\" class=\"ProDetailinput\" value=\"" + list_ProductsDetail[i].StockNum + "\"  /></td>";
                        TrRows += "	<td>";
                        TrRows += "		<input id=\"SalePrice" + list_ProductsDetail[i].ID + "\" onblur=\"SetCtrlValue('#txtTradePrice',$(this).attr('name'));\" type=\"text\" name=\"SalePrice\" class=\"ProDetailinput\" value=\"" + list_ProductsDetail[i].SalePrice + "\" /></td>";
                        TrRows += "	<td>";
                        TrRows += "		<input id=\"MarketPrice" + list_ProductsDetail[i].ID + "\" onblur=\"SetCtrlValue('#txtMarketPrice',$(this).attr('name'));\"  type=\"text\" name=\"MarketPrice\" class=\"ProDetailinput\" value=\"" + list_ProductsDetail[i].MarketPrice + "\" /></td>";
                        TrRows += "	<td>";
                        TrRows += "		<input id=\"CostPrice" + list_ProductsDetail[i].ID + "\" onblur=\"SetCtrlValue('#txtCostPrice',$(this).attr('name'));\"  type=\"text\" name=\"CostPrice\" class=\"ProDetailinput\" value=\"" + list_ProductsDetail[i].CostPrice + "\" /></td>";
                        TrRows += "	<td>";
                        TrRows += "		<input id=\"ProDetailWeight" + list_ProductsDetail[i].ID + "\" type=\"text\" name=\"ProDetailWeight\" class=\"ProDetailinput\" value=\"" + list_ProductsDetail[i].ProDetailWeight + "\" /></td>";
                        TrRows += "	<td>";
                        TrRows += "		<input id=\"Allocation" + list_ProductsDetail[i].ID + "\" type=\"text\" name=\"Allocation\" class=\"ProDetailinput\" value=\"" + list_ProductsDetail[i].Allocation + "\" maxlength=\"50\" /></td>";
                        TrRows += "	<td>";
                        TrRows += "	<select id=\"IsShow" + list_ProductsDetail[i].ID + "\" name=\"IsShow\">";
                        string value0 = "";
                        string value1 = "";
                        if (list_ProductsDetail[i].IsShow.ToString() == "0")
                        {
                            value0 = "selected='selected'";
                        }
                        else
                        {
                            value1 = "selected='selected'";
                        }
                        TrRows += "			<option value=\"1\" " + value1 + ">是</option>";
                        TrRows += "			<option value=\"0\" " + value0 + ">否</option>";
                        TrRows += "	</select></td>";
                        TrRows += "</tr>";
                    }
                    AddTr += TrRows;
                    AddTr += "</table>";
                    lbtopEdit.Text = AddTr;
                }
                #endregion

                //SEO优化
                var seoInfo = new BLL.CNVP_SEOInfo().GetSingle_CNVP_SEOInfoById(model.SeoInfoID);
                if (seoInfo != null)
                {
                    txtOriginTitle.Text = seoInfo.OriginTitle;
                    txtOriginKey.Text = seoInfo.OriginKey;
                    txtOriginDescription.Text = seoInfo.OriginDescription;
                }
            }
        }

        protected void btUp_Click(object sender, EventArgs e)
        {
            #region 后台验证
            if (ddlProductClassID.SelectedValue == "0")
            {
                BasePage.MessageBoxGoHistory("请选择所属类别！");
            }
            if (ddlProductTypeID.SelectedValue == "0")
            {
                BasePage.MessageBoxGoHistory("请选择所属类型！");
            }
            if (txtProductName.Text == "")
            {
                BasePage.MessageBoxGoHistory("请输入商品名称！");
            }
            if (!string.IsNullOrEmpty(Request.Form["Standard"])&&!string.IsNullOrEmpty(Request.Form["StandardName"]))
            {
                string[] Standard_Array = Request.Form["Standard"].Split(Convert.ToChar(","));
                string[] StandardName_Array = Request.Form["StandardName"].Split(Convert.ToChar(","));
                for (var i = 0; i < Standard_Array.Length; i++)
                {
                    string[] StandardValueID = Request.Form["StandardValueID" + Standard_Array[i] + ""].Split(Convert.ToChar(","));
                    for (var k = 0; k < StandardValueID.Length; k++)
                    {
                        if (StandardValueID[k].ToString() == "0" || StandardValueID[k].ToString() == "")
                        {
                            BasePage.MessageBoxGoHistory("" + StandardName_Array[i] + "请选择！");
                        }
                    }

                }
            }
            #endregion
            if (id > 0)
            {
                #region 修改
                try
                {
                    int rows = new BLL.CNVP_Products().Update_CNVP_Products(new Model.CNVP_Products()
                    {
                        ID = id,
                        ProductClassID = int.Parse(ddlProductClassID.SelectedValue),
                        ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue),
                        ProductName = txtProductName.Text,
                        ProductCode = txtProductCode.Text,
                        UpTime = DateTime.Now.AddSeconds(1),
                        DownTime = DateTime.Now.AddSeconds(1),
                        EditTime = DateTime.Now.AddSeconds(1),
                        KeyWords = txtKeyWords.Text,
                        BrandID = int.Parse(Request.Form["listBranks"]),
                        ProductUnit = txtProductUnit.Text,
                        Intro = txtIntro.Text,
                        Detaile = FCKeditor1.Value,
                        ProductState = byte.Parse(rblProductState.SelectedValue),
                        MarketPrice = decimal.Parse(txtMarketPrice.Text),
                        CostPrice = decimal.Parse(txtCostPrice.Text),
                        TradePrice = decimal.Parse(txtTradePrice.Text),
                        ProductNo = txtProductNo.Text,
                        ProductWeight = decimal.Parse(txtProductWeight.Text),
                        StockTotalNum = int.Parse(txtStockTotalNum.Text),
                        Allocation = txtAllocation.Text,
                        ProductTags = txtProductTags.Text,
                        StandardIDs = Standard.Value,
                        StandardValues = StandardName.Value,
                        ImgProLoad = Request.Form["txtImgProLoad"],
                        SeoInfoID = int.Parse(ViewState["seoInId"].ToString()),
                        HotLink = txtHotLink.Text.Trim(),
                        AllowReview=byte.Parse(rbAllowReview.SelectedValue),
                        DeliveryFreightID = Convert.ToInt32(ddlDeliveryFreight.SelectedValue)

                    });

                    //BasePage.MessageBox(Request.Form["txtImgProLoad"].ToString());
                    #region 图片插入
                    CNVP_ProductsPic bll_ProductsPic = new CNVP_ProductsPic();
                    bll_ProductsPic.Delete_CNVP_ProductsPicByProductID(id);
                    try
                    {
                        string PicAddress1_Str = "";
                        string PicAddress2_Str = "";
                        string PicAddress3_Str = "";
                        string PicAddress4_Str = "";
                        string UploadImg = Request.Form["cbUploadImg"];
                        if (UploadImg != null)
                        {
                            string[] cbUploadImg = UploadImg.Split(Convert.ToChar(","));
                            for (int i = 0; i < cbUploadImg.Length; i++)//注意从‘0’开始
                            {
                                string[] PicAddress1 = Request.Form["PicAddressA"].Split(Convert.ToChar(","));
                                PicAddress1_Str = PicAddress1[i].ToString();
                                string[] PicAddress2 = Request.Form["PicAddressB"].Split(Convert.ToChar(","));
                                PicAddress2_Str = PicAddress2[i].ToString();
                                string[] PicAddress3 = Request.Form["PicAddressC"].Split(Convert.ToChar(","));
                                PicAddress3_Str = PicAddress3[i].ToString();
                                string[] PicAddress4 = Request.Form["PicAddressD"].Split(Convert.ToChar(","));
                                PicAddress4_Str = PicAddress4[i].ToString();
                                int rows_pic = new BLL.CNVP_ProductsPic().Add_CNVP_ProductsPic(new Model.CNVP_ProductsPic()
                                {
                                    ProductID = id,
                                    SmallPic = PicAddress1_Str,
                                    BigPic = PicAddress3_Str,
                                    Pic = PicAddress2_Str,
                                    OriginalPic = PicAddress4_Str
                                });
                            }
                        }
                    }
                    catch { }
                    #endregion
                    #region 产品详细表
                    string nowid = "";//存储当前ID
                    try
                    {
                        string ProDetailNo_Str = "";
                        int StockNum_Int = 0;
                        decimal SalePrice_Decimal = 0;
                        decimal CostPrice_Decimal = 0;
                        decimal MarketPrice_Decimal = 0;
                        int ProDetailWeight_Int = 0;
                        string Allocation_Str = "";
                        byte IsShow_Byte = 0;
                        string[] CKProDetail = Request.Form["CKProDetail"].Split(Convert.ToChar(","));
                        for (int i = 0; i < CKProDetail.Length; i++)//注意从‘0’开始
                        {
                            string[] ProDetailNo = Request.Form["ProDetailNo"].Split(Convert.ToChar(","));
                            ProDetailNo_Str = ProDetailNo[i].ToString();

                            //获取规格值
                            string StandardValueID_Str = "";
                            string[] StandardArray = Request.Form["Standard"].Split(Convert.ToChar(","));//规格
                            for (int k = 0; k < StandardArray.Length; k++)
                            {
                                string[] StandardValueIDs = Request.Form["StandardValueID" + StandardArray[k] + ""].Split(Convert.ToChar(","));//规格值
                                StandardValueID_Str += StandardValueIDs[i].ToString() + ",";
                            }
                            string StandardValueArray = StandardValueID_Str.Substring(0, StandardValueID_Str.Length - 1);

                            string[] StockNum = Request.Form["StockNum"].Split(Convert.ToChar(","));
                            try
                            {
                                StockNum_Int = int.Parse(StockNum[i].ToString());
                            }
                            catch { StockNum_Int = 0; }
                            string[] SalePrice = Request.Form["SalePrice"].Split(Convert.ToChar(","));
                            try
                            {
                                SalePrice_Decimal = decimal.Parse(SalePrice[i].ToString());
                            }
                            catch { SalePrice_Decimal = 0; }
                            string[] CostPrice = Request.Form["CostPrice"].Split(Convert.ToChar(","));
                            try
                            {
                                CostPrice_Decimal = decimal.Parse(CostPrice[i].ToString());
                            }
                            catch { CostPrice_Decimal = 0; }
                            string[] MarketPrice = Request.Form["MarketPrice"].Split(Convert.ToChar(","));
                            try
                            {
                                MarketPrice_Decimal = decimal.Parse(MarketPrice[i].ToString());
                            }
                            catch { MarketPrice_Decimal = 0; }
                            string[] ProDetailWeight = Request.Form["ProDetailWeight"].Split(Convert.ToChar(","));
                            try
                            {
                                ProDetailWeight_Int = int.Parse(ProDetailWeight[i].ToString());
                            }
                            catch { ProDetailWeight_Int = 0; }
                            string[] Allocation = Request.Form["Allocation"].Split(Convert.ToChar(","));
                            Allocation_Str = Allocation[i].ToString();
                            string[] IsShow = Request.Form["IsShow"].Split(Convert.ToChar(","));
                            IsShow_Byte = byte.Parse(IsShow[i].ToString());
                            int CKid = 0;
                            //string xx = cbUploadImg[i].ToString();
                            if (CKProDetail[i].ToString() != "on")//注意不空
                            {
                                CKid = int.Parse(CKProDetail[i].ToString());
                            }
                            if (CKid > 0)
                            {
                                int rows_Detail = new BLL.CNVP_ProductsDetail().Update_CNVP_ProductsDetail(new Model.CNVP_ProductsDetail()
                                {
                                    ID = CKid,
                                    ProDetailNo = ProDetailNo_Str,
                                    StandardValueIDs = StandardValueArray,
                                    StockNum = StockNum_Int,
                                    SalePrice = SalePrice_Decimal,
                                    CostPrice = CostPrice_Decimal,
                                    MarketPrice = MarketPrice_Decimal,
                                    ProDetailWeight = ProDetailWeight_Int,
                                    Allocation = Allocation_Str,
                                    IsShow = IsShow_Byte,
                                    ProductID = id //主产品【ID】
                                });
                                nowid += CKid + ",";
                            }
                            else
                            {
                                //添加后返回当前ID
                                int rows_Detail = new BLL.CNVP_ProductsDetail().Add_CNVP_ProductsDetail(new Model.CNVP_ProductsDetail()
                                {
                                    ProDetailNo = ProDetailNo_Str,
                                    StandardValueIDs = StandardValueArray,
                                    StockNum = StockNum_Int,
                                    SalePrice = SalePrice_Decimal,
                                    CostPrice = CostPrice_Decimal,
                                    MarketPrice = MarketPrice_Decimal,
                                    ProDetailWeight = ProDetailWeight_Int,
                                    Allocation = Allocation_Str,
                                    IsShow = IsShow_Byte,
                                    ProductID = id //主产品【ID】
                                });
                                nowid += rows_Detail + ",";
                            }
                        }
                    }
                    catch { }
                    //删除不在当前的ID
                    if (nowid.Length > 0)
                    {
                        nowid = nowid.Substring(0, nowid.Length - 1);
                    }
                    else
                    {
                        nowid = "0";
                    }
                    new BLL.CNVP_ProductsDetail().Delete_CNVP_ProductsDetailNotIn(id, nowid);

                    #endregion
                    #region 扩展属性
                    string nowid_ExtendeProperty = "";//存储当前ID
                    try
                    {
                        string RefExtendProperty_Str = "";
                        int RefExtendProperty_Int = 0;
                        string[] CKRefExtendProperty = Request.Form["CKRefExtendProperty"].Split(Convert.ToChar(","));
                        for (int i = 0; i < CKRefExtendProperty.Length; i++)
                        {
                            string[] RefExtendPropertyID = Request.Form["RefExtendPropertyID"].Split(Convert.ToChar(","));
                            RefExtendProperty_Int = int.Parse(RefExtendPropertyID[i].ToString());
                            string[] RefExtendProperty = Request.Form["RefExtendProperty"].Split(Convert.ToChar(","));
                            RefExtendProperty_Str = RefExtendProperty[i].ToString();
                            int CKid = 0;
                            if (CKRefExtendProperty[i].ToString() != "on")//注意不空
                            {
                                CKid = int.Parse(CKRefExtendProperty[i].ToString());
                            }
                            if (CKid > 0)
                            {
                                int rows_ExtendeProperty = new BLL.CNVP_ProExtendeProperty().Update_CNVP_ProExtendeProperty(new Model.CNVP_ProExtendeProperty()
                                {
                                    ID = CKid,
                                    ProductID = id, //主产品【ID】
                                    StandardVaule = RefExtendProperty_Str,
                                    ProTypeRefExtendPropertyID = RefExtendProperty_Int,
                                    ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue)
                                });
                                nowid_ExtendeProperty += CKid + ",";
                            }
                            else
                            {
                                int rows_ExtendeProperty = new BLL.CNVP_ProExtendeProperty().Add_CNVP_ProExtendeProperty(new Model.CNVP_ProExtendeProperty()
                                {
                                    ProductID = id, //主产品【ID】
                                    StandardVaule = RefExtendProperty_Str,
                                    ProTypeRefExtendPropertyID = RefExtendProperty_Int,
                                    ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue)
                                });
                                nowid_ExtendeProperty += rows_ExtendeProperty + ",";
                            }

                        }
                    }
                    catch { }
                    //删除不在当前的ID
                    if (nowid_ExtendeProperty.Length > 0)
                    {
                        nowid_ExtendeProperty = nowid_ExtendeProperty.Substring(0, nowid_ExtendeProperty.Length - 1);
                    }
                    else
                    {
                        nowid_ExtendeProperty = "0";
                    }
                    new BLL.CNVP_ProExtendeProperty().DeleteNotInID(id,nowid_ExtendeProperty);
                    #endregion
                    #region 属性参数
                    string nowid_PropertyDescripttion = "";//存储当前ID
                    try
                    {
                        string RefDescripttion_Str = "";
                        int RefDescripttion_Int = 0;
                        string[] CKRefDescripttion = Request.Form["CKRefDescripttion"].Split(Convert.ToChar(","));
                        for (int i = 0; i < CKRefDescripttion.Length; i++)
                        {
                            string[] RefDescripttionID = Request.Form["RefDescripttionID"].Split(Convert.ToChar(","));
                            RefDescripttion_Int = int.Parse(RefDescripttionID[i].ToString());
                            string[] RefDescripttion = Request.Form["RefDescripttion"].Split(Convert.ToChar(","));
                            RefDescripttion_Str = RefDescripttion[i].ToString();
                            int CKid = 0;
                            if (CKRefDescripttion[i].ToString() != "on")//注意不空
                            {
                                CKid = int.Parse(CKRefDescripttion[i].ToString());
                            }
                            if (CKid > 0)
                            {
                                int rows_PropertyDescripttion = new BLL.CNVP_ProPropertyDescripttion().Update_CNVP_ProPropertyDescripttion(new Model.CNVP_ProPropertyDescripttion()
                                {
                                    ID = CKid,
                                    ProductID = id, //主产品【ID】
                                    StandardValue = RefDescripttion_Str,
                                    ProTypeRefDescripttionID = RefDescripttion_Int,
                                    ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue)
                                });
                                nowid_PropertyDescripttion += CKid + ",";
                            }
                            else
                            {
                                int rows_PropertyDescripttion = new BLL.CNVP_ProPropertyDescripttion().Add_CNVP_ProPropertyDescripttion(new Model.CNVP_ProPropertyDescripttion()
                                {
                                    ProductID = id, //主产品【ID】
                                    StandardValue = RefDescripttion_Str,
                                    ProTypeRefDescripttionID = RefDescripttion_Int,
                                    ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue)
                                });
                                nowid_PropertyDescripttion += rows_PropertyDescripttion + ",";
                            }
                        }
                    }
                    catch { }
                    //删除不在当前的ID
                    if (nowid_PropertyDescripttion.Length > 0)
                    {
                        nowid_PropertyDescripttion = nowid_PropertyDescripttion.Substring(0, nowid_PropertyDescripttion.Length - 1);
                    }
                    else
                    {
                        nowid_PropertyDescripttion = "0";
                    }
                    new BLL.CNVP_ProPropertyDescripttion().DeleteNotInID(id, nowid_PropertyDescripttion);
                    #endregion
                    
                    int seoInfo = new BLL.CNVP_SEOInfo().Update_CNVP_SEOInfo(new Model.CNVP_SEOInfo()
                    {
                        ID = int.Parse(ViewState["seoInId"].ToString()),
                        OriginTitle = txtOriginTitle.Text.Trim(),
                        OriginKey = txtOriginKey.Text.Trim(),
                        OriginDescription = txtOriginDescription.Text.Trim()
                    });
                    if (TypeEdit == "up")
                    {
                        BasePage.MessageBox("修改成功！", "ProductListUp.aspx?Page=" + Request.QueryString["Page"] + "");
                    }
                    else if (TypeEdit == "down")
                    {
                        BasePage.MessageBox("修改成功！", "ProductListDown.aspx?Page=" + Request.QueryString["Page"] + "");
                    }
                    else if (TypeEdit == "clear")
                    {
                        BasePage.MessageBox("修改成功！", "ProductListClear.aspx?Page=" + Request.QueryString["Page"] + "");
                    }
                    else
                    {
                        BasePage.MessageBox("修改成功！", "ProductList.aspx?Page=" + Request.QueryString["Page"] + "");
                    }
                    DataInfo(id);
                }
                catch
                {
                    BasePage.MessageBoxGoHistory("修改失败！");
                }
                #endregion
            }
            else
            {
                try
                {
                    int rows_SeoInfo = new BLL.CNVP_SEOInfo().Add_CNVP_SEOInfo(new Model.CNVP_SEOInfo()
                    {
                        OriginTitle = txtOriginTitle.Text.Trim(),
                        OriginKey = txtOriginKey.Text.Trim(),
                        OriginDescription = txtOriginDescription.Text.Trim()
                    });
                    #region 添加
                    int rows = new BLL.CNVP_Products().Add_CNVP_Products(new Model.CNVP_Products()
                    {
                        ProductClassID = int.Parse(ddlProductClassID.SelectedValue),
                        ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue),
                        ProductName = txtProductName.Text,
                        ProductCode = txtProductCode.Text,
                        KeyWords = txtKeyWords.Text,
                        BrandID = int.Parse(Request.Form["listBranks"]),
                        ProductUnit = txtProductUnit.Text,
                        Intro = txtIntro.Text,
                        Detaile = FCKeditor1.Value,
                        ProductState = byte.Parse(rblProductState.SelectedValue),
                        MarketPrice = decimal.Parse(txtMarketPrice.Text),
                        CostPrice = decimal.Parse(txtCostPrice.Text),
                        TradePrice = decimal.Parse(txtTradePrice.Text),
                        ProductNo = txtProductNo.Text,
                        ProductWeight = decimal.Parse(txtProductWeight.Text),
                        StockTotalNum = int.Parse(txtStockTotalNum.Text),
                        Allocation = txtAllocation.Text,
                        AddTime = DateTime.Now.AddSeconds(1),
                        ProductTags = txtProductTags.Text,
                        StandardIDs = Standard.Value,
                        StandardValues = StandardName.Value,
                        ImgProLoad = Request.Form["txtImgProLoad"],
                        IsDelete=0,
                        SeoInfoID = rows_SeoInfo,
                        HotLink=txtHotLink.Text.Trim(),
                        AllowReview=byte.Parse(rbAllowReview.SelectedValue),
                        DeliveryFreightID=Convert.ToInt32(ddlDeliveryFreight.SelectedValue)

                    });
                    int MaxID = rows;//取产品最大值
                    #region 图片插入
                    try
                    {
                        string PicAddress1_Str = "";
                        string PicAddress2_Str = "";
                        string PicAddress3_Str = "";
                        string PicAddress4_Str = "";
                        string UploadImg = Request.Form["cbUploadImg"];
                        if (UploadImg != null)
                        {
                            string[] cbUploadImg = UploadImg.Split(Convert.ToChar(","));
                            for (int i = 0; i < cbUploadImg.Length; i++)//注意从‘0’开始
                            {
                                string[] PicAddress1 = Request.Form["PicAddressA"].Split(Convert.ToChar(","));
                                PicAddress1_Str = PicAddress1[i].ToString();
                                string[] PicAddress2 = Request.Form["PicAddressB"].Split(Convert.ToChar(","));
                                PicAddress2_Str = PicAddress2[i].ToString();
                                string[] PicAddress3 = Request.Form["PicAddressC"].Split(Convert.ToChar(","));
                                PicAddress3_Str = PicAddress3[i].ToString();
                                string[] PicAddress4 = Request.Form["PicAddressD"].Split(Convert.ToChar(","));
                                PicAddress4_Str = PicAddress4[i].ToString();
                                int rows_pic = new BLL.CNVP_ProductsPic().Add_CNVP_ProductsPic(new Model.CNVP_ProductsPic()
                                {
                                    ProductID = MaxID,
                                    SmallPic = PicAddress1_Str,
                                    BigPic = PicAddress3_Str,
                                    Pic = PicAddress2_Str,
                                    OriginalPic = PicAddress4_Str
                                });
                            }
                        }
                    }
                    catch { }
                    #endregion
                    #region 产品详细表
                    try
                    {
                        string ProDetailNo_Str = "";
                        int StockNum_Int = 0;
                        decimal SalePrice_Decimal = 0;
                        decimal CostPrice_Decimal = 0;
                        decimal MarketPrice_Decimal = 0;
                        int ProDetailWeight_Int = 0;
                        string Allocation_Str = "";
                        byte IsShow_Byte = 0;
                        string[] CKProDetail = Request.Form["CKProDetail"].Split(Convert.ToChar(","));
                        for (int i = 0; i < CKProDetail.Length; i++)//注意从‘0’开始
                        {
                            string[] ProDetailNo = Request.Form["ProDetailNo"].Split(Convert.ToChar(","));
                            ProDetailNo_Str = ProDetailNo[i].ToString();

                            //获取规格值
                            string StandardValueID_Str = "";
                            string[] StandardArray = Request.Form["Standard"].Split(Convert.ToChar(","));//规格
                            for (int k = 0; k < StandardArray.Length; k++)
                            {
                                string[] StandardValueIDs = Request.Form["StandardValueID" + StandardArray[k] + ""].Split(Convert.ToChar(","));//规格值
                                StandardValueID_Str += StandardValueIDs[i].ToString() + ",";
                            }
                            string StandardValueArray = StandardValueID_Str.Substring(0, StandardValueID_Str.Length - 1);

                            string[] StockNum = Request.Form["StockNum"].Split(Convert.ToChar(","));
                            try
                            {
                                StockNum_Int = int.Parse(StockNum[i].ToString());
                            }
                            catch { StockNum_Int = 0; }
                            string[] SalePrice = Request.Form["SalePrice"].Split(Convert.ToChar(","));
                            try
                            {
                                SalePrice_Decimal = decimal.Parse(SalePrice[i].ToString());
                            }
                            catch { SalePrice_Decimal = 0; }
                            string[] CostPrice = Request.Form["CostPrice"].Split(Convert.ToChar(","));
                            try
                            {
                                CostPrice_Decimal = decimal.Parse(CostPrice[i].ToString());
                            }
                            catch { CostPrice_Decimal = 0; }
                            string[] MarketPrice = Request.Form["MarketPrice"].Split(Convert.ToChar(","));
                            try
                            {
                                MarketPrice_Decimal = decimal.Parse(MarketPrice[i].ToString());
                            }
                            catch { MarketPrice_Decimal = 0; }
                            string[] ProDetailWeight = Request.Form["ProDetailWeight"].Split(Convert.ToChar(","));
                            try
                            {
                                ProDetailWeight_Int = int.Parse(ProDetailWeight[i].ToString());
                            }
                            catch { ProDetailWeight_Int = 0; }
                            string[] Allocation = Request.Form["Allocation"].Split(Convert.ToChar(","));
                            Allocation_Str = Allocation[i].ToString();
                            string[] IsShow = Request.Form["IsShow"].Split(Convert.ToChar(","));
                            IsShow_Byte = byte.Parse(IsShow[i].ToString());
                            int rows_Detail = new BLL.CNVP_ProductsDetail().Add_CNVP_ProductsDetail(new Model.CNVP_ProductsDetail()
                            {
                                ProDetailNo = ProDetailNo_Str,
                                StandardValueIDs = StandardValueArray,
                                StockNum = StockNum_Int,
                                SalePrice = SalePrice_Decimal,
                                CostPrice = CostPrice_Decimal,
                                MarketPrice = MarketPrice_Decimal,
                                ProDetailWeight = ProDetailWeight_Int,
                                Allocation = Allocation_Str,
                                IsShow = IsShow_Byte,
                                ProductID = MaxID //主产品【ID】
                            });
                        }
                    }
                    catch { }
                    #endregion
                    #region 扩展属性
                    try
                    {
                        string RefExtendProperty_Str = "";
                        int RefExtendProperty_Int = 0;
                        string[] RefExtendPropertyID = Request.Form["RefExtendPropertyID"].Split(Convert.ToChar(","));
                        for (int i = 0; i < RefExtendPropertyID.Length; i++)
                        {
                            string[] RefExtendProperty = Request.Form["RefExtendProperty"].Split(Convert.ToChar(","));
                            RefExtendProperty_Str = RefExtendProperty[i].ToString();
                            RefExtendProperty_Int = int.Parse(RefExtendPropertyID[i].ToString());
                            int rows_ExtendeProperty = new BLL.CNVP_ProExtendeProperty().Add_CNVP_ProExtendeProperty(new Model.CNVP_ProExtendeProperty()
                            {
                                ProductID = MaxID, //主产品【ID】
                                StandardVaule = RefExtendProperty_Str,
                                ProTypeRefExtendPropertyID = RefExtendProperty_Int,
                                ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue)
                            });
                        }
                    }
                    catch { }
                    #endregion
                    #region 属性参数
                    try
                    {
                        string RefDescripttion_Str = "";
                        int RefDescripttion_Int = 0;
                        string[] RefDescripttionID = Request.Form["RefDescripttionID"].Split(Convert.ToChar(","));
                        for (int i = 0; i < RefDescripttionID.Length; i++)
                        {
                            string[] RefDescripttion = Request.Form["RefDescripttion"].Split(Convert.ToChar(","));
                            RefDescripttion_Str = RefDescripttion[i].ToString();
                            RefDescripttion_Int = int.Parse(RefDescripttionID[i].ToString());
                            int rows_PropertyDescripttion = new BLL.CNVP_ProPropertyDescripttion().Add_CNVP_ProPropertyDescripttion(new Model.CNVP_ProPropertyDescripttion()
                            {
                                ProductID = MaxID, //主产品【ID】
                                StandardValue = RefDescripttion_Str,
                                ProTypeRefDescripttionID = RefDescripttion_Int,
                                ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue)
                            });
                        }
                    }
                    catch { }
                    #endregion

                    #endregion
                    if (TypeEdit == "up")
                    {
                        BasePage.MessageBox("添加成功,并返回列表！", "ProductListUp.aspx");
                    }
                    else if (TypeEdit == "down")
                    {
                        BasePage.MessageBox("添加成功,并返回列表！", "ProductListDown.aspx");
                    }
                    else
                    {
                        BasePage.MessageBox("添加成功,并返回列表！", "ProductList.aspx");
                    }
                }
                catch
                {
                    BasePage.MessageBoxGoHistory("添加失败！");
                }
            }
        }

        protected void btUp1_Click(object sender, EventArgs e)
        {
            try
            {
                #region 后台验证
                if (ddlProductClassID.SelectedValue == "0")
                {
                    BasePage.MessageBoxGoHistory("请选择所属类别！");
                }
                if (ddlProductTypeID.SelectedValue == "0")
                {
                    BasePage.MessageBoxGoHistory("请选择所属类型！");
                }
                if (txtProductName.Text == "")
                {
                    BasePage.MessageBoxGoHistory("请输入商品名称！");
                }
                if (!string.IsNullOrEmpty(Request.Form["Standard"]) && !string.IsNullOrEmpty(Request.Form["StandardName"]))
                {
                    string[] Standard_Array = Request.Form["Standard"].Split(Convert.ToChar(","));
                    string[] StandardName_Array = Request.Form["StandardName"].Split(Convert.ToChar(","));
                    for (var i = 0; i < Standard_Array.Length; i++)
                    {
                        string[] StandardValueID = Request.Form["StandardValueID" + Standard_Array[i] + ""].Split(Convert.ToChar(","));
                        for (var k = 0; k < StandardValueID.Length; k++)
                        {
                            if (StandardValueID[k].ToString() == "0" || StandardValueID[k].ToString() == "")
                            {
                                BasePage.MessageBoxGoHistory("" + StandardName_Array[i] + "请选择！");
                            }
                        }

                    }
                }
                #endregion
                int rows_SeoInfo = new BLL.CNVP_SEOInfo().Add_CNVP_SEOInfo(new Model.CNVP_SEOInfo()
                {
                    OriginTitle = txtOriginTitle.Text.Trim(),
                    OriginKey = txtOriginKey.Text.Trim(),
                    OriginDescription = txtOriginDescription.Text.Trim()
                });
                #region 添加
                int rows = new BLL.CNVP_Products().Add_CNVP_Products(new Model.CNVP_Products()
                {
                    ProductClassID = int.Parse(ddlProductClassID.SelectedValue),
                    ProductTypeID = int.Parse(ddlProductTypeID.SelectedValue),
                    ProductName = txtProductName.Text,
                    ProductCode = txtProductCode.Text,
                    KeyWords = txtKeyWords.Text,
                    BrandID = int.Parse(Request.Form["listBranks"]),
                    ProductUnit = txtProductUnit.Text,
                    Intro = txtIntro.Text,
                    Detaile = FCKeditor1.Value,
                    ProductState = byte.Parse(rblProductState.SelectedValue),
                    MarketPrice = decimal.Parse(txtMarketPrice.Text),
                    CostPrice = decimal.Parse(txtCostPrice.Text),
                    TradePrice = decimal.Parse(txtTradePrice.Text),
                    ProductNo = txtProductNo.Text,
                    ProductWeight = decimal.Parse(txtProductWeight.Text),
                    StockTotalNum = int.Parse(txtStockTotalNum.Text),
                    Allocation = txtAllocation.Text,
                    AddTime = DateTime.Now.AddSeconds(1),
                    ProductTags = txtProductTags.Text,
                    StandardIDs = Standard.Value,
                    StandardValues = StandardName.Value,
                    ImgProLoad = Request.Form["txtImgProLoad"],
                    IsDelete = 0,
                    SeoInfoID = rows_SeoInfo,
                    HotLink = txtHotLink.Text.Trim(),
                    AllowReview=byte.Parse(rbAllowReview.SelectedValue),
                    DeliveryFreightID = Convert.ToInt32(ddlDeliveryFreight.SelectedValue)
                });
                
                int MaxID = rows;//取产品最大值
                #region 图片插入
                try
                {
                    string PicAddress1_Str = "";
                    string PicAddress2_Str = "";
                    string PicAddress3_Str = "";
                    string PicAddress4_Str = "";
                    string UploadImg = Request.Form["cbUploadImg"];
                    if (UploadImg != null)
                    {
                        string[] cbUploadImg = UploadImg.Split(Convert.ToChar(","));
                        for (int i = 0; i < cbUploadImg.Length; i++)//注意从‘0’开始
                        {
                            string[] PicAddress1 = Request.Form["PicAddressA"].Split(Convert.ToChar(","));
                            PicAddress1_Str = PicAddress1[i].ToString();
                            string[] PicAddress2 = Request.Form["PicAddressB"].Split(Convert.ToChar(","));
                            PicAddress2_Str = PicAddress2[i].ToString();
                            string[] PicAddress3 = Request.Form["PicAddressC"].Split(Convert.ToChar(","));
                            PicAddress3_Str = PicAddress3[i].ToString();
                            string[] PicAddress4 = Request.Form["PicAddressD"].Split(Convert.ToChar(","));
                            PicAddress4_Str = PicAddress4[i].ToString();
                            int rows_pic = new BLL.CNVP_ProductsPic().Add_CNVP_ProductsPic(new Model.CNVP_ProductsPic()
                            {
                                ProductID = MaxID,
                                SmallPic = PicAddress1_Str,
                                BigPic = PicAddress3_Str,
                                Pic = PicAddress2_Str,
                                OriginalPic = PicAddress4_Str
                            });
                        }
                    }
                }
                catch { }
                #endregion
                #region 产品详细表
                try
                {
                    string ProDetailNo_Str = "";
                    int StockNum_Int = 0;
                    decimal SalePrice_Decimal = 0;
                    decimal CostPrice_Decimal = 0;
                    decimal MarketPrice_Decimal = 0;
                    int ProDetailWeight_Int = 0;
                    string Allocation_Str = "";
                    byte IsShow_Byte = 0;
                    string[] CKProDetail = Request.Form["CKProDetail"].Split(Convert.ToChar(","));
                    for (int i = 0; i < CKProDetail.Length; i++)//注意从‘0’开始
                    {
                        string[] ProDetailNo = Request.Form["ProDetailNo"].Split(Convert.ToChar(","));
                        ProDetailNo_Str = ProDetailNo[i].ToString();

                        //获取规格值
                        string StandardValueID_Str = "";
                        string[] StandardArray = Request.Form["Standard"].Split(Convert.ToChar(","));//规格
                        for (int k = 0; k < StandardArray.Length; k++)
                        {
                            string[] StandardValueIDs = Request.Form["StandardValueID" + StandardArray[k] + ""].Split(Convert.ToChar(","));//规格值
                            StandardValueID_Str += StandardValueIDs[i].ToString() + ",";
                        }
                        string StandardValueArray = StandardValueID_Str.Substring(0, StandardValueID_Str.Length - 1);

                        string[] StockNum = Request.Form["StockNum"].Split(Convert.ToChar(","));
                        try
                        {
                            StockNum_Int = int.Parse(StockNum[i].ToString());
                        }
                        catch { StockNum_Int = 0; }
                        string[] SalePrice = Request.Form["SalePrice"].Split(Convert.ToChar(","));
                        try
                        {
                            SalePrice_Decimal = decimal.Parse(SalePrice[i].ToString());
                        }
                        catch { SalePrice_Decimal = 0; }
                        string[] CostPrice = Request.Form["CostPrice"].Split(Convert.ToChar(","));
                        try
                        {
                            CostPrice_Decimal = decimal.Parse(CostPrice[i].ToString());
                        }
                        catch { CostPrice_Decimal = 0; }
                        string[] MarketPrice = Request.Form["MarketPrice"].Split(Convert.ToChar(","));
                        try
                        {
                            MarketPrice_Decimal = decimal.Parse(MarketPrice[i].ToString());
                        }
                        catch { MarketPrice_Decimal = 0; }
                        string[] ProDetailWeight = Request.Form["ProDetailWeight"].Split(Convert.ToChar(","));
                        try
                        {
                            ProDetailWeight_Int = int.Parse(ProDetailWeight[i].ToString());
                        }
                        catch { ProDetailWeight_Int = 0; }
                        string[] Allocation = Request.Form["Allocation"].Split(Convert.ToChar(","));
                        Allocation_Str = Allocation[i].ToString();
                        string[] IsShow = Request.Form["IsShow"].Split(Convert.ToChar(","));
                        IsShow_Byte = byte.Parse(IsShow[i].ToString());
                        int rows_Detail = new BLL.CNVP_ProductsDetail().Add_CNVP_ProductsDetail(new Model.CNVP_ProductsDetail()
                        {
                            ProDetailNo = ProDetailNo_Str,
                            StandardValueIDs = StandardValueArray,
                            StockNum = StockNum_Int,
                            SalePrice = SalePrice_Decimal,
                            CostPrice = CostPrice_Decimal,
                            MarketPrice = MarketPrice_Decimal,
                            ProDetailWeight = ProDetailWeight_Int,
                            Allocation = Allocation_Str,
                            IsShow = IsShow_Byte,
                            ProductID = MaxID //主产品【ID】
                        });
                    }
                }
                catch { }
                #endregion
                #region 扩展属性
                try
                {
                    string RefExtendProperty_Str = "";
                    int RefExtendProperty_Int = 0;
                    string[] RefExtendPropertyID = Request.Form["RefExtendPropertyID"].Split(Convert.ToChar(","));
                    for (int i = 0; i < RefExtendPropertyID.Length; i++)
                    {
                        string[] RefExtendProperty = Request.Form["RefExtendProperty"].Split(Convert.ToChar(","));
                        RefExtendProperty_Str = RefExtendProperty[i].ToString();
                        RefExtendProperty_Int = int.Parse(RefExtendPropertyID[i].ToString());
                        int rows_ExtendeProperty = new BLL.CNVP_ProExtendeProperty().Add_CNVP_ProExtendeProperty(new Model.CNVP_ProExtendeProperty()
                        {
                            ProductID = MaxID, //主产品【ID】
                            StandardVaule = RefExtendProperty_Str,
                            ProTypeRefExtendPropertyID = RefExtendProperty_Int
                        });
                    }
                }
                catch { }
                #endregion
                #region 属性参数
                try
                {
                    string RefDescripttion_Str = "";
                    int RefDescripttion_Int = 0;
                    string[] RefDescripttionID = Request.Form["RefDescripttionID"].Split(Convert.ToChar(","));
                    for (int i = 0; i < RefDescripttionID.Length; i++)
                    {
                        string[] RefDescripttion = Request.Form["RefDescripttion"].Split(Convert.ToChar(","));
                        RefDescripttion_Str = RefDescripttion[i].ToString();
                        RefDescripttion_Int = int.Parse(RefDescripttionID[i].ToString());
                        int rows_PropertyDescripttion = new BLL.CNVP_ProPropertyDescripttion().Add_CNVP_ProPropertyDescripttion(new Model.CNVP_ProPropertyDescripttion()
                        {
                            ProductID = MaxID, //主产品【ID】
                            StandardValue = RefDescripttion_Str,
                            ProTypeRefDescripttionID = RefDescripttion_Int
                        });
                    }
                }
                catch { }
                #endregion

                #endregion
                BasePage.MessageBoxGoHistory("添加成功,并继续！");
            }
            catch
            {
                BasePage.MessageBoxGoHistory("添加失败！");
            }
        }
    }
}
